<template>
	<view class="address-module" v-if="masterOrderDetail">
		<view class="main">
			<view class="user-detail">
				<view class="user-name">
					{{masterOrderDetail.customer_name}}
				</view>
				<view class="user-phone">
					{{masterOrderDetail.customer_phone}}
				</view>
			</view>
			<view class="address-detail">
				{{fullAddress}}
			</view>
		</view>
		<view class="change-btn" >
			{{postMethods}}
		</view>
		<view class="courier-number" v-if="masterOrderDetail.logistics === DELIVER_STATUS.DELIVERED">
			快递单号：{{masterOrderDetail.distribution_type===DELIVER_TYPE.EXPRESS?masterOrderDetail.courier_number:'线下自提无单号'}}
			<i class="iconfont icon-copy" v-if="masterOrderDetail.logistics === DELIVER_STATUS.DELIVERED" @click="copyCourierNumber"/>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { defineProps,computed } from 'vue';
	import {IMasterOrderDetail} from "../../types";
	import {DELIVER_TYPE,DELIVER_STATUS} from '@/enum/deliver';
	import global from '@/global';
	
	interface IProps{
		masterOrderDetail:IMasterOrderDetail|null
	}
	
	const props = withDefaults(defineProps<IProps>(),{
		masterOrderDetail:null
	})
	
	const fullAddress = computed(()=>{
		if(!props.masterOrderDetail) return ''
		return `${props.masterOrderDetail.pro}  ${props.masterOrderDetail.city}  ${props.masterOrderDetail.area}  ${props.masterOrderDetail.address}`
	})
	
	const postMethods = computed(()=>{
		if(!props.masterOrderDetail) return 
		return global.deliverOptionList[props.masterOrderDetail.distribution_type].name
	})
	
	const copyCourierNumber = ()=>{
		uni.setClipboardData({
			data: props.masterOrderDetail!.courier_number!,
			success: () => {
				uni.prompt.$showToast('已复制快递单号')
			}
		});
	}

</script>

<style scoped lang="scss">
	@import "./addressModule.scss";
</style>